#include "SocEmu.h"
#include <getopt.h>

const struct option SocEmu::long_options[] = {
    { "image",          1, NULL, 'i' },
    { "help",           0, NULL, 'h' },
    { 0,                0, NULL,  0  }
};

void SocEmu::print_help(const char *file) {
    printf("Usage: %s [OPTION...]\n", file);
    printf("\n");
    printf("  -i, --image=FILE      run with this image file\n");
    printf("  -h, --help            print program help info\n");
    printf("\n");
}

vector<const char *> SocEmu::parse_args(int argc, const char *argv[])
{
    vector<const char *> args = { argv[0] };
    int o;
    extern uint64_t getLogLevel(const char * str);
    while ( (o = getopt_long(argc, const_cast<char *const*>(argv), "hi:", long_options, NULL)) != -1) {
        switch (o) {
            case 'i': this->flash_image = optarg;
                    args.push_back("-i");
                    args.push_back(optarg);
                    break;
            default:
                    print_help(argv[0]);
                    exit(0);
        }
    }
    Verilated::commandArgs(argc, argv);
    return args;
}

SocEmu::~SocEmu()
{
    delete dut_ptr;
}